import { Button, Switch, Tooltip } from 'antd';
import { EyeOutlined, EditOutlined } from '@ant-design/icons';
import { tableMoreBtnConfig } from '@/utils/myutilConfig';
import { ManageCommonAPI } from '@/pages/type';
import { Fragment } from 'react';
import { history } from 'umi';
import { getKeyRouter, tooltipLength } from '@/utils';
import pageStyles from '@/common/pageLayout.less';
import { warcloseService, waropenService } from '../services/ManageServices';
import { display } from 'html2canvas/dist/types/css/property-descriptors/display';
import MyIcon from '@/components/MyIcon';

// 操作按钮
const Operation = (curRes: Record<string, any>, operateFuns: Record<string, any>, record: Record<string, any>) => {
  let operationArray: any = [];

  /** 一个按钮都没有时展示*/
  const Disable = (
    <Fragment key={record?.id + '--Disable'}>
      <Button style={{ color: '#000' }} className="manageBtntTxtStyle" type={'link'} size={'small'} disabled>
        --
      </Button>
    </Fragment>
  );

  /** 更多按钮配置 */
  const otherBtnConfig: any = [
    {
      icon: <EditOutlined />,
      btnName: '编辑',
      clickFnc: operateFuns,
      clickType: 'onEdit',
      isVisible: curRes?.['/assetStore/edit'],
      // isVisible: true
    },
  ];
  const ohterBtn = tableMoreBtnConfig(otherBtnConfig, record);
  operationArray = ohterBtn;
  operationArray = operationArray?.filter((itemBtn: any) => itemBtn);
  return operationArray && operationArray?.length > 0 ? operationArray : [Disable];
};

const getTableColumns = (curRes: Record<string, any>, operateFuns: WarnManageAPI.IOperationClick, onSearch) => {
  return [
    {
      title: '仓库名称',
      dataIndex: 'storeName',
      key: 'storeName',
      width: 300,
      visible: true,
      render: (text: string, record: Record<string, any>) => {
        return (
          <Tooltip title={tooltipLength(text, 50)}>
            <span className={pageStyles['over-flow-hidden']}>
              <div style={{ color: '100%', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
                {/* {!record.childs? <MyIcon type="icon-dian" isTheme={false} /> : ''} */}
                {text}
              </div>
            </span>
          </Tooltip>
        );
      },
    },
    {
      title: '仓库位置',
      dataIndex: 'storePlace',
      key: 'storePlace',
      visible: true,
      width: 180,
      render: (text: string | null, record: Record<string, any>) => {
        return <div style={{ color: '100%', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{text}</div>;
      },
    },
    {
      title: '状态',
      dataIndex: 'storeState',
      key: 'storeState',
      visible: true,
      width: 180,
      render: (text: string | null, record: Record<string, any>) => {
        return (
          <div style={{ color: '100%', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
            <Switch
              checkedChildren="启用"
              unCheckedChildren="禁用"
              onChange={(checked) => {
                if (checked) {
                  waropenService(record);
                } else {
                  warcloseService(record);
                }
              }}
              defaultChecked={text == '1' ? true : false}
            />
          </div>
        );
      },
    },
    {
      title: '仓库所属单位',
      dataIndex: 'storeCompanyName',
      key: 'storeCompanyName',
      visible: true,
      width: 150,
      // sorter: (a: any, b: any) => (a.ownTime > b.ownTime ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '仓库管理员',
      dataIndex: 'storeUserName',
      key: 'storeUserName',
      visible: true,
      width: 150,
      // sorter: (a: any, b: any) => (a.ownerID > b.ownerID ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '仓库管理员电话',
      dataIndex: 'storeDutyPhone',
      key: 'storeDutyPhone',
      visible: true,
      width: 150,
      // sorter: (a: any, b: any) => (a.ownPositionID > b.ownPositionID ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '仓库接管员',
      dataIndex: 'ownerID',
      key: 'ownerID',
      visible: false,
      width: 150,
      // sorter: (a: any, b: any) => (a.ownDepartmentID > b.ownDepartmentID ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '仓库接管员岗位',
      dataIndex: 'ownPositionID',
      key: 'ownPositionID',
      visible: false,
      width: 150,
      // sorter: (a: any, b: any) => (a.ownCompanyID > b.ownCompanyID ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '接管员部门',
      dataIndex: 'ownDepartmentID',
      key: 'ownDepartmentID',
      visible: false,
      width: 150,
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '接管员单位',
      dataIndex: 'ownCompanyID',
      key: 'ownCompanyID',
      visible: false,
      width: 150,
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '操作',
      dataIndex: 'operation',
      key: 'operation',
      width: 80,
      visible: true,
      unDrag: true,
      align: 'center',
      fixed: 'right',
      render: (text: any, record: any) => {
        return (
          <div
            style={{
              display: 'flex',
            }}
          >
            {Operation(curRes, operateFuns, record)}
          </div>
        );
      },
    },
  ];
};

export { getTableColumns };
